package com.sgb.kjwl.view.ui.adapter.packers;

import android.content.Context;
import android.view.ViewGroup;
import android.widget.LinearLayout;
import android.widget.TextView;

import androidx.core.content.ContextCompat;

import com.sgb.kjwl.BR;
import com.sgb.kjwl.R;
import com.sgb.kjwl.model.entity.PackersPersonEntity;
import com.sgb.kjwl.view.widget.FlowLayout;
import com.swgk.core.recyclerview.adapter.BaseRecycleAdapter;
import com.swgk.core.recyclerview.adapter.ItemViewHolder;
import com.swgk.core.util.MDateUtil;

import java.util.List;

/**
*@author 毁灭霸者
*@date 2019/6/5
*description:
*/
public class PackersPersonAdapter extends BaseRecycleAdapter<PackersPersonEntity> {

    public PackersPersonAdapter(Context context, List<PackersPersonEntity> data) {
        super(context, R.layout.item_packers_person, data);
    }

    @Override
    public void convert(ItemViewHolder holder, final PackersPersonEntity entity) {
        holder.setBinding(BR.viewModel, entity);
        TextView timeView = holder.getItem().findViewById(R.id.time_view);
        try {
            timeView.setText(MDateUtil.getByTimestamp(Long.parseLong(entity.getTime()), MDateUtil.Format.FORMART5.name));
        } catch (NumberFormatException e) {
            e.fillInStackTrace();
        }

        FlowLayout flSkills = holder.getItem().findViewById(R.id.fl_skills);
        LinearLayout.LayoutParams layoutParams = new LinearLayout.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT);
        layoutParams.setMargins(5, 3, 5, 3);
        if (flSkills != null) {
            flSkills.removeAllViews();
        }
        String[] split = entity.getSp().split("/");
        for (String s : split) {
            TextView tv = new TextView(context);
            tv.setTextSize(12);
            tv.setPadding(28, 5, 28, 5);
            tv.setText(s);
            tv.setTextColor(ContextCompat.getColor(context,R.color.color_0286DF));
            tv.setMaxEms(10);
            tv.setSingleLine();
            tv.setBackgroundResource(R.drawable.corner_blue_shape);
            tv.setLayoutParams(layoutParams);
            if (flSkills != null) {
                flSkills.addView(tv, layoutParams);
            }
        }

    }
}
